<?php

declare(strict_types=1);

namespace App\Rpc;

use Hyperf\Contract\ContainerInterface;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Utils\ApplicationContext;

/**
 * 用户中心rpc调度器
 */
#[RpcService(['name' => 'UserCenterService', 'protocol' => 'jsonrpc-http', 'server' => 'jsonrpc-http', 'publishTo' => 'nacos'])]
class Dispatcher
{
    protected string $rpcBaseNamespace = '\App\Rpc\\';

    /**
     * 请求入口
     * @param String $rpcName
     * @param array $param
     * @return mixed
     */
    public function request(String $rpcName, string $method, array $param): mixed
    {
        $rpc = ApplicationContext::getContainer()->get($this->rpcBaseNamespace.$rpcName);
        return $rpc->$method(...$param);
    }
}
